import functools

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    def __repr__(self):
        return "[{},{}]".format(self.x, self.y)

class Building:
    def __init__(self, param):
        self.left = param[0]
        self.right = param[1]
        self.height = param[2]
    
    def __getitem__(self, i):
        if i==0: return self.left
        elif i==1: return self.right
        else: return self.height

    def __hash__(self):
        return self.left + self.right + self.height

class Solution(object):
    def getSkyline(self, buildings):
        """
        :type buildings: List[List[int]]
        :rtype: List[List[int]]
        """
        # get all critical points
        buildings = [Building(param) for param in buildings]
        # all possible critical points
        points = []
        tmp = set()
        for b in buildings:
            tmp.add(b[0])
            tmp.add(b[1])
        points = list(tmp)
        points.sort()

        # assciate building to critical points
        bDict = {}
        for b in buildings:
            if b[0] not in bDict:
                bDict.update({b[0]:set()})
            bDict[b[0]].add(b)
            if b[1] not in bDict:
                bDict.update({b[1]:set()})
            bDict[b[1]].add(b)
        
        # get height of critical point
        tmp = []
        bSet = set()
        for p in points:
            for b in bDict[p]:
                if b in bSet: bSet.remove(b)
                else: bSet.add(b)
            if len(bSet)==0:
                tmp.append(Point(p, 0))
            else:
                height = max(map(lambda b:b[2], bSet))
                tmp.append(Point(p, height))
        
        # unique points in one horizontal line
        result = []
        begin = 0
        end = 0
        while end<len(tmp):
            while end<len(tmp) and tmp[begin].y==tmp[end].y: end+=1
            p = tmp[begin]
            result.append([p.x, p.y])
            begin = end
        return result

print(Solution().getSkyline([[2,9,10], [2, 9, 1], [3,7,15], [5,12,12], [15,20,10], [19,24,8]] ))